<?php 
session_start();
$id_user = $_SESSION["id_user"];
require_once "connexion.php";
require_once "Model/factureModel.php";
require_once "Model/clientModel.php";
require_once "Model/userModel.php";
//Appel au singleton Connexion
$maConnexion = ConnexionSingleton::getInstance();
$maConnexion->Connect();
$user = new userModel();
?>
<div id="message" style="float:left;height:25px;width:100%;"> </div>
<div class="div_facture_facture" id="div_facture_facture">
	<?php 
			$facture = new factureModel();
			$tab_facture = $facture->getfacture(15);
			echo "<table id='tablefacture' class='tabfacture' width='100%'>";
			echo "<tr class='fond_tr'><td colspan='7' style='color:#404146;'> Liste des Factures </td></tr>";
			echo "<tr style='color:#488BD2;background:#fff;'><td class='tab_td_style'> ID</td><td class='tab_td_style'> Montant </td><td class='tab_td_style'> Date Facture</td><td class='tab_td_style'> Client</td><td class='tab_td_style'> Utilisateur </td><td class='tab_td_style'>Date devis</td><td class='tab_td_style'></td></tr>";
			foreach($tab_facture as $key => $value)
			{
				echo "<tr id='".$value['id']."' style='background:#fff;'>";
				echo "<td class='tab_td_style'>".$value["id"]."</td>";
				echo "<td class='tab_td_style'>".$value["montant"]."</td>";
				echo "<td class='tab_td_style'>".$value["dateFacture"]."</td>";
				echo "<td class='tab_td_style'>".$value["client"]."</td>";
				echo "<td class='tab_td_style'>".$value["utilisateur"]."</td>";
				echo "<td class='tab_td_style'>".$value["dateDevis"]."</td>";
				echo "<td class='tab_td_style'>";
				if($user->getStatut($id_user) == 1)
				{
					echo "<a class='delete'>";
					echo "<img src='css/images/supprimer.png' id='supression'>"; 
					echo "</a>";
				}
				echo "</td>";
				echo "</tr>";	
			}
			
		?>
		<script>
			$('table#tablefacture td a.delete').live("click",function()
			{
				if (confirm("Etes vous sur de vouloir supprimer l'enregistrement ?"))
				{
					var id = $(this).parent().parent().attr('id');
					var data = 'id_facture='+id;
					var parent = $(this).parent().parent();

					$.ajax(
					{
						   type: "POST",
						   url: "Controller/factureController.php?suppression",
						   data: data,
						   cache: false,

						   success: function(msg)
						   {
								$('#message').html(msg);
								parent.fadeOut('slow', function() {$(this).remove();});
						   }
					 });
				}
			});
		</script>
</div>